// utils/component/advertising/advertising.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    datas: []
    },

  /**
   * 组件的方法列表
   */
  methods: {
    
    prepare() {
      var self = this;
      getApp().func.Post(false, getApp().api.advertising, { "userId": getApp().globalData.userId }, function (res) {
        if (res.items == null || res.items.length == 0){
          self.setData({
            show: false
          })
        }else{
          self.setData({
            show: true,
            datas: res.items
          })
        }
      })

    },

    didTapImage: function (e) {
      let index = e.currentTarget.dataset.index
      if (this.data.datas[index].action == "pages/happyJelly/jellyHome/jellyHome" || 
        this.data.datas[index].action == "pages/home/home" || 
        this.data.datas[index].action == "pages/addProduct/shareproducts/shareProduct" || 
        this.data.datas[index].action == "pages/mine/message/message" || 
        this.data.datas[index].action == "pages/mine/mine") {
        wx.switchTab({
          url: "../../" + this.data.datas[index].action
        })
        return
      }
      wx.navigateTo({
        url: "../../" + this.data.datas[index].action
      })
    },
   
    close:function(e){
      var arr = this.data.datas
      if (arr.length == 1){
        this.setData({
          show: false,
        })
      }else{
        arr.pop()
        this.setData({
          datas: arr,
        })
      }
    },
   
  }
})
